/**
 * 
 */
package No301_400.No321_330.OddEvenLinkedList_328;

/** 
 * @author  作者 E-mail: ttljtw@qq.com
 * @date 创建时间：2017年3月4日 下午9:33:53 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
/**
 * @author 李敬
 * 
 */
public class Solution {
	public static ListNode oddEvenList(ListNode head) {
		if (head == null || head.next == null) {
			return head;
		}
		ListNode ret = head;
		ListNode h1 = head;
		ListNode h2 = head.next;
		ListNode last = h2;
		head = head.next.next;
		int i = 3;
		while (head != null) {
			if (i % 2 != 0) {
				h1.next = head;
				h1 = head;
			} else {
				h2.next = head;
				h2 = head;
			}
			head = head.next;
			i++;
		}
		h1.next = last;
		h2.next = null;
		return ret;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ListNode a = new ListNode(0);
		ListNode b = new ListNode(1);
		ListNode c = new ListNode(2);
		ListNode d = new ListNode(3);
		a.next = b;
		b.next = c;
		c.next = d;
		ListNode ret = oddEvenList(a);
		System.out.println(1);
	}

}

class ListNode {
	int val;
	ListNode next;

	ListNode(int x) {
		val = x;
	}
}
